package com.flashextended.apps.logomaker.view.core.background
{
	import flash.display.Sprite;
	
	import mx.core.UIComponent;
	import mx.events.ResizeEvent;

	public class CoreBackground extends UIComponent
	{
		private var background:Sprite;
		private var backgroundWhite:Sprite;
		
		public function CoreBackground()
		{
			super();
			settings();
			this.addEventListener(ResizeEvent.RESIZE, containerResize);
		}
		private function settings():void
		{
			this.percentWidth = 100;
			this.percentHeight = 100;
		}
		
		private function drawLines():void
		{
			try{
				this.removeChild(background);
				this.removeChild(backgroundWhite);
			}catch(e:Error){};
			
			backgroundWhite = new Sprite();
			backgroundWhite.graphics.beginFill(0xFFFFFF, 1);
			backgroundWhite.graphics.drawRect(0, 0, this.width, this.height);
			backgroundWhite.graphics.endFill();
			this.addChild(backgroundWhite);
			
			background = new Sprite();
			this.addChild(background);
			background.graphics.lineStyle(1, 0xf1f1f1);
			var pasX:Number = 0;
			var pasY:Number = 10;
			var maxX:Number = Math.round(this.width/pasX);
			var maxY:Number = Math.round(this.height/pasY);
			background.graphics.moveTo(pasX, pasY);
			
			for(var i:int=0;i<maxY-1;i++)
			{
				background.graphics.moveTo(pasX, pasY);
				background.graphics.lineTo(this.width, pasY);
				pasY+=10;
			}
			pasX = 10;
			pasY = 0;
			maxX = Math.round(this.width/pasX);
			for(var j:int=0;j<maxX-1;j++)
			{
				background.graphics.moveTo(pasX, pasY);
				background.graphics.lineTo(pasX, this.height);
				pasX+=10;
			}			
		}		
		
		private function containerResize(e:ResizeEvent):void
		{
			drawLines();
		}				
		
	}
}